package com.toman.Adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.toman.Entity.Search_Entity;
import com.toman.MyApplication;
import com.toman.R;

import java.util.ArrayList;

/**
 * Created by  GridView_adpter on Administrator on 2017/11/3 on 16:13.
 */

public class Search_adpter extends BaseAdapter {

    //上下文对象
    Context context;
    //
    ArrayList<Search_Entity> arrayList;

    LayoutInflater inflater;

    //进度条
    ProgressBar mProgressBar;
    MyApplication myApplication;

    public Search_adpter(Context context, ArrayList<Search_Entity> arrayList, MyApplication myApplication) {
        this.context = context;
        this.arrayList = arrayList;
        this.myApplication = myApplication;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return arrayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        AddPackage addPackage;
        //       if (null == convertView){
        addPackage = new AddPackage();
        convertView = inflater.inflate(R.layout.search_item, null, false);
        addPackage.img = (ImageView) convertView.findViewById(R.id.mSearchImg);
        addPackage.title = (TextView) convertView.findViewById(R.id.mSearchTitle);
        mProgressBar = (ProgressBar) convertView.findViewById(R.id.mProgressBar);
        addPackage.percent = (TextView) convertView.findViewById(R.id.mPercent);

//            convertView.setTag(addPackage);
//        }else {
//            addPackage=(AddPackage) convertView.getTag();
//        }
        mProgressBar.setProgressDrawable(context.getResources().getDrawable(R.drawable.my_progress_horizontal));
        // addPackage.percent.setTextColor(context.getResources().getColor(R.color.loginbg));
     /*   if(myApplication.getSp().getString("token","").equals("toman")){
        }else if(myApplication.getSp().getString("token","").equals("operater")){
            mProgressBar.setProgressDrawable(context.getResources().getDrawable(R.drawable.my_progress_horizonta2));
            addPackage.percent.setTextColor(context.getResources().getColor(R.color.g7bg1));

        }else if(myApplication.getSp().getString("token","").equals("company")){
            mProgressBar.setProgressDrawable(context.getResources().getDrawable(R.drawable.my_progress_horizonta3));
            addPackage.percent.setTextColor(context.getResources().getColor(R.color.c1));
        }*/

        //addPackage.img.setBackgroundResource(arrayList.get(position).getImg());

        addPackage.title.setText(arrayList.get(position).getTitle());

        addPackage.percent.setText(arrayList.get(position).getProgress() + "%");
        mProgressBar.setProgress(arrayList.get(position).getProgress());


        return convertView;
    }


    public class AddPackage {
        ImageView img;
        TextView title;
        TextView percent;
    }


}
